 
package com.heima.wemedia.controller.v1;
 
import com.heima.common.constants.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.format.ResolverStyle;

@RestController
@RequestMapping("/api/v1/news")
@RequiredArgsConstructor
public class WmNewsController {

    private final WmNewsService wmNewsService;
 
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.findAll(dto);
    }


    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto){
        return  wmNewsService.submitNews(dto);
    }

    /**
     * 文章，查看详情
     * @param id
     * @return
     */
    @GetMapping("one/{id}")
    public ResponseResult article_details(@PathVariable Integer id){
        return wmNewsService.article_details(id);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del_news")
    public ResponseResult del_news(@PathVariable Integer id){
        return wmNewsService.del_news(id);
    }

    @PostMapping("/down_or_up")
    public ResponseResult down_or_up(@RequestBody WmNewsDto dto){
        return wmNewsService.down_or_up(dto);
    }

    /**
     * 查看文章列表
     */
    @PostMapping("/list_vo")
    public ResponseResult list_vo(@RequestBody NewsAuthDto dto){
        return wmNewsService.list_vo(dto);
    }

    @GetMapping("/one_vo/{id}")
    public ResponseResult OneById(@PathVariable Integer id){
        return wmNewsService.OneById(id);
    }

    @PostMapping("/auth_fail")
    public ResponseResult AuthFail(@RequestBody NewsAuthDto dto){
        return wmNewsService.AuthStatus(dto,WemediaConstants.WM_NEWS_AUTH_FAIL);
    }

    @PostMapping("/auth_pass")
    public ResponseResult AuthPass(@RequestBody NewsAuthDto dto){
        return wmNewsService.AuthStatus(dto, WemediaConstants.WM_NEWS_AUTH_PASS);
    }

}